package com.run.fjy.util;

import java.util.Calendar;

public class DateUtil {
	
	public static final String DAY = "day";
	public static final String WEEK = "week";
	public static final String MONTH = "month";
	
	private static Calendar calendar = Calendar.getInstance();
	
	public static Integer getDay(long timestamp) {
		calendar.setTimeInMillis(timestamp);
		return calendar.get(Calendar.YEAR)*10000+(1+calendar.get(Calendar.MONTH))*100+calendar.get(Calendar.DAY_OF_MONTH);
	}

	
	public static Integer getWeek(long timestamp) {
		calendar.setTimeInMillis(timestamp);
		return calendar.get(Calendar.YEAR)*100+calendar.get(Calendar.WEEK_OF_YEAR);
	}
	
	public static Integer getMonth(long timestamp) {
		calendar.setTimeInMillis(timestamp);
		return calendar.get(Calendar.YEAR)*100+(1+calendar.get(Calendar.MONTH));
	}
	
	/**
	 * 根据指定的字符串类型的 类型 返回相应的整型日期值。
	 * @param type 
	 * @return
	 */
	public static Integer getDate(String type, Long timestamp) {
		switch (type) {
		case DAY:
			return getDay(timestamp);
		case WEEK:
			return getWeek(timestamp);
		case MONTH:
			return getMonth(timestamp);
		default:
			return getDay(timestamp);
		}
	}
}
